

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Fly542">
  <meta name="keywords" content="">
  
    <meta name="description" content="惯例首选name语法DNS规范试图使构建的域名规则尽可能通用。这一想法的精髓是任何现有对象的名称经过尽量小的改变都能表示为域名。但是在为对象分配域名时，谨慎的用户将选择即满足域名系统规则，又满足对象任何现有规则的名称，无论这些规则是公开出版的还是由现有程序暗示的。如：当命名邮件域时，用于应当即满足本备忘录的规则，又满足RFC-822宏的规则。创建新的主机名时，应当遵守旧的HOSTS.TXT规则。这">
<meta property="og:type" content="article">
<meta property="og:title" content="DNS协议介绍">
<meta property="og:url" content="http://fly542.cn/2020/08/26/03%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91/03linux/01DNS%E5%8D%8F%E8%AE%AE/index.html">
<meta property="og:site_name" content="Fly542 技术沉淀">
<meta property="og:description" content="惯例首选name语法DNS规范试图使构建的域名规则尽可能通用。这一想法的精髓是任何现有对象的名称经过尽量小的改变都能表示为域名。但是在为对象分配域名时，谨慎的用户将选择即满足域名系统规则，又满足对象任何现有规则的名称，无论这些规则是公开出版的还是由现有程序暗示的。如：当命名邮件域时，用于应当即满足本备忘录的规则，又满足RFC-822宏的规则。创建新的主机名时，应当遵守旧的HOSTS.TXT规则。这">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://fly542.cn/2020/08/26/03%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91/03linux/01DNS%E5%8D%8F%E8%AE%AE/srv.png">
<meta property="article:published_time" content="2020-08-26T13:10:15.000Z">
<meta property="article:modified_time" content="2024-06-20T06:28:11.685Z">
<meta property="article:author" content="Fly542">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="dns">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://fly542.cn/2020/08/26/03%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91/03linux/01DNS%E5%8D%8F%E8%AE%AE/srv.png">
  
  
  <title>DNS协议介绍 - Fly542 技术沉淀</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"fly542.cn","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Fly542 技术沉淀</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="DNS协议介绍">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-08-26 21:10" pubdate>
        2020年8月26日 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      20k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      171 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">DNS协议介绍</h1>
            
            <div class="markdown-body">
              <h1 id="惯例"><a href="#惯例" class="headerlink" title="惯例"></a>惯例</h1><h2 id="首选name语法"><a href="#首选name语法" class="headerlink" title="首选name语法"></a>首选name语法</h2><p>DNS规范试图使构建的域名规则尽可能通用。这一想法的精髓是任何现有对象的名称经过尽量小的改变都能表示为域名。<br>但是在为对象分配域名时，谨慎的用户将选择即满足域名系统规则，又满足对象任何现有规则的名称，无论这些规则是公开出版的还是由现有程序暗示的。<br>如：当命名邮件域时，用于应当即满足本备忘录的规则，又满足RFC-822宏的规则。创建新的主机名时，应当遵守旧的HOSTS.TXT规则。这可避免当旧软件被转换为使用域名时出现问题<br>以下语法(BNF范式)将减少许多使用域名的应用程序（例如邮件，TELNET）的问题。</p>
<figure class="highlight bnf"><table><tr><td class="gutter"><div class="code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div></td><td class="code"><pre><code class="hljs bnf"><span class="hljs-attribute">&lt;domain&gt;</span> ::= &lt;subdomain&gt; | <span class="hljs-string">&quot; &quot;</span><br><span class="hljs-attribute">&lt;subdomain&gt;</span> ::= &lt;label&gt; | &lt;subdomain&gt;<span class="hljs-string">&quot;.&quot;</span> &lt;label&gt;<br><span class="hljs-attribute">&lt;label&gt;</span> ::= &lt;letter&gt; [[&lt;ldh-str&gt;] &lt;let-dig&gt;]<br><span class="hljs-attribute">&lt;ldh-str&gt;</span> ::= &lt;let-dig-hyp&gt; | &lt;let-dig-hyp&gt; &lt;ldh-str&gt;<br><span class="hljs-attribute">&lt;let-dig-hyp&gt;</span> ::= &lt;let-dig&gt; “-”<br><span class="hljs-attribute">&lt;let-dig&gt;</span> ::= &lt;letter&gt; | &lt;digit&gt;<br><span class="hljs-attribute">&lt;letter&gt;</span> ::= 52个字母字符A到Z中的任何一个（大写）和a到z中的小写<br><span class="hljs-attribute">&lt;digit&gt;</span> ::= 十个数字0到9中的任何一个<br></code></pre></td></tr></table></figure>
<h1 id="DNS报文格式"><a href="#DNS报文格式" class="headerlink" title=" DNS报文格式"></a><span id=dformat> DNS报文格式</span></h1><p>整个报文的格式如下，包括了五部分组成。</p>
<figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-code">+---------------------+</span><br><span class="hljs-section">|        Header       | 报文头</span><br><span class="hljs-section">+---------------------+</span><br><span class="hljs-section">|       Question      | 查询请求</span><br><span class="hljs-section">+---------------------+</span><br><span class="hljs-section">|        Answer       | 应答</span><br><span class="hljs-section">+---------------------+</span><br><span class="hljs-section">|      Authority      | 授权应答</span><br><span class="hljs-section">+---------------------+</span><br><span class="hljs-section">|      Additional     | 附加信息</span><br><span class="hljs-section">+---------------------+</span><br></code></pre></td></tr></table></figure>

<p>详细介绍如下。</p>
<ul>
<li>Header 必选，定义了报文是请求还是应答、错误码以及其它的一些标志位；</li>
<li>Question 描述了查询的请求报文，包括查询类型(QTYPE)、查询类(QCLASS) 以及查询的域名(QNAME)；</li>
</ul>
<p>剩下的3个段包含相同的格式:一系列可能为空的<a href="#rr">资源记录(RR)</a>。 Answer段包含回答问题的RR列表；Authority段包含授权域名服务器的RR列表； <span id=additional> Additional</span>段包含和请求相关的RR列表，但这些附件的RR不是必须回答的。</p>
<h2 id="报文头-Header"><a href="#报文头-Header" class="headerlink" title="报文头(Header)"></a>报文头(Header)</h2><p>DNS的报文头由固定的12个字节构成。</p>
<figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--+<br><span class="hljs-section">|                      ID                       |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|QR|  Opcode   |AA|TC|RD|RA|   Z    |   RCODE   |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                    QDCOUNT                    |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                    ANCOUNT                    |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                    NSCOUNT                    |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                    ARCOUNT                    |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br></code></pre></td></tr></table></figure>

<p>字段介绍如下：</p>
<table>
<thead>
<tr>
<th>字段简写</th>
<th>字段长度</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>ID</td>
<td>16 bits无符号整数</td>
<td>客户端设置，响应报文会原样带回，用于客户端区分不同的请求应答；</td>
</tr>
<tr>
<td>QR</td>
<td>1 bit</td>
<td>区分是请求还是应答<br>0 请求<br>1 应答</td>
</tr>
<tr>
<td>Opcode</td>
<td>4 bits</td>
<td>设置查询的种类，响应报文会原样带回.<br> 0 标准查询 QUERY；<br> 1 反向查询 IQUERY；<br> 2 服务器状态查询 STATUS；<br> 5 增量更新<br> 3~15 保留；</td>
</tr>
<tr>
<td>AA</td>
<td>1bit</td>
<td>授权应答 AuthoritativeAnswer，响应报文生效，用于标示服务器响应报文是否为授权服务器返回的结果，可能是在本地 Cache 的缓存；</td>
</tr>
<tr>
<td>TC</td>
<td>1bit</td>
<td>截断 TrunCation，报文因为超过了允许的长度，导致被截断；</td>
</tr>
<tr>
<td>RD</td>
<td>1bit</td>
<td>用于请求报文，代表期望是否使用递归查询；<br>0 不使用递归查询<br>1 使用递归查询</td>
</tr>
<tr>
<td>RA</td>
<td>1bit</td>
<td>用于响应报文中，表示服务端是否支持递归查询<br>0 不支持递归<br>1 支持递归</td>
</tr>
<tr>
<td>RCODE</td>
<td>4 bits</td>
<td>应答码 ResponseCode，会在响应报文中设置。<br> 0 没有错误；<br> 1 报文格式错误(Format Error)，服务器解析请求报文时报错<br> 2 服务器失败(Server Failure)，意思是服务器失败，也就是这个域名的权威服务器拒绝响应或者响应REFUSE，递归服务器返回Rcode值为2给CLIENT<br> 3 名字错误(Name Error)，对应的DNS应答状态为NXDOMAIN，意思是不存在的记录，也就是这个具体的域名在权威服务器中并不存在<br>  4 没有实现(Not Implemented)，域名服务器不支持查询类型<br>  5 拒绝(Refused)，由于服务器设置的策略拒绝给出应答，通常是安全的配置；也就是这个请求源IP不在服务的范围内<br>  6-15 保留值，暂未使用。</td>
</tr>
<tr>
<td>QDCOUNT</td>
<td>16 bits 无符号整数</td>
<td>请求段中的<a href="#rr">RR</a>数</td>
</tr>
<tr>
<td>ANCOUNT</td>
<td>16 bits 无符号整数</td>
<td>应答段中的<a href="#rr">RR</a>数,</td>
</tr>
<tr>
<td>NSCOUNT</td>
<td>16 bits 无符号整数</td>
<td>报文授权段中的授权<a href="#rr">RR</a>数</td>
</tr>
<tr>
<td>ARCOUNT</td>
<td>16 bits 无符号整数</td>
<td>报文附加段中的附加<a href="#rr">RR</a>数</td>
</tr>
</tbody></table>
<h2 id="查询请求-Question"><a href="#查询请求-Question" class="headerlink" title="查询请求(Question)"></a>查询请求(Question)</h2><p>用来标识，查询的请求参数，同时需要在头中设置 <code>QDCOUNT</code> 这个字段。</p>
<figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--+<br>|                                               |<br>/                     QNAME                     /<br><span class="hljs-section">/                                               /</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                     QTYPE                     |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                     QCLASS                    |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br></code></pre></td></tr></table></figure>

<p>字段含义如下:</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th>长度</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>QNAME</td>
<td>最大255字节</td>
<td>标签字符串</td>
<td>域名被编码为一些labels序列，每个labels包含一个字节表示后续字符串长度，以及这个字符串，以0长度和空字符串来表示域名结束。注意这个字段可能为奇数字节，不需要进行边界填充对齐。</td>
</tr>
<tr>
<td>QTYPE</td>
<td>2字节</td>
<td>无符号整数</td>
<td>表示查询类型, 取值可以为任何可用的类型值，该字段的值包括对<a href="#rr_type">TYPE</a>字段有效的所有代码，以及一些更通用的代码，这些代码可以匹配一种以上的RR, 以及通配码来表示所有的RR记录。</td>
</tr>
<tr>
<td>QCLASS</td>
<td>2 字节</td>
<td>无符号整数</td>
<td>表示查询的协议类，<br> 0 保留 <br> 1 Internet (IN)<br> 2  未使用<br> 3 Chaos (CH) <br> 4 Hesiod (HS) <br> 5-253 未使用<br> 254 QCLASS NONE <br> 255 QCLASS * (ANY)</td>
</tr>
</tbody></table>
<h1 id="DNS-RR介绍"><a href="#DNS-RR介绍" class="headerlink" title="DNS RR介绍"></a><span id="rr">DNS RR介绍</span></h1><p>DNS资源记录（Resource Record，简称RR）</p>
<p>DNS server 内的每一个域名都有自己的域文件(zone file)，zone file 是由多个记录组成的，每一个记录就被称为资源记录(Resource Record，简称RR)。</p>
<h2 id="RR-记录格式"><a href="#RR-记录格式" class="headerlink" title="RR 记录格式"></a><span id="rr_format">RR 记录格式</span></h2><p>所有的RR具有以下相同的格式</p>
<figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-section">  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br>|                                               |<br>/                                               /<br>/                      NAME                     /<br><span class="hljs-section">|                                               |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                      TYPE                     |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                     CLASS                     |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br>|                      TTL                      |<br><span class="hljs-section">|                                               |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br>|                   RDLENGTH                    |<br><span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--|<br>/                     RDATA                     /<br><span class="hljs-section">/                                               /</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br></code></pre></td></tr></table></figure>
<p>各个字段说明如下：</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th>长度</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>NAME</td>
<td>最大255字节</td>
<td>标签字符串</td>
<td>不定长与之前QNAME相同,这里会使用省略字段<br>为了压缩消息总长度此内容可能会采用<a href="#compress">消息压缩</a>方式存储。</td>
</tr>
<tr>
<td>TYPE</td>
<td>2字节</td>
<td>无符号整数</td>
<td>资源类型，是QTYPE的子集</td>
</tr>
<tr>
<td>CLASS</td>
<td>2字节</td>
<td>无符号整数</td>
<td>与之前的QCLASS相同</td>
</tr>
<tr>
<td>TTL</td>
<td>4字节</td>
<td>有符号整数</td>
<td>它指定在再次查询信息源之前可以缓存资源记录的时间间隔。零值被解释为表示RR仅可用于进行中的事务，不应缓存。例如，SOA记录始终以零TTL分发，以禁止缓存。零值也可以用于易失性数据。</td>
</tr>
<tr>
<td>RDLENGTH</td>
<td>2字节</td>
<td>无符号整数</td>
<td>后面跟随的RDATA的长度</td>
</tr>
<tr>
<td>RDATA</td>
<td></td>
<td></td>
<td>真实的数据内容</td>
</tr>
</tbody></table>
<h3 id="消息压缩"><a href="#消息压缩" class="headerlink" title="消息压缩"></a><span id="compress">消息压缩</span></h3><p>为了减小dns消息的大小，dns协议中针对域名采用了一种压缩方案，消除了消息中重复的域名。压缩方式为：使用2个字节的指针来指向消息中已经存在相同域名的位置。</p>
<figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--+<br><span class="hljs-section">| 1  1|                OFFSET                   |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br></code></pre></td></tr></table></figure>
<p>第一个字节的前2个bit为11时表示此域名采用的压缩格式，后面的OFFSET (14 bit) 是当前域名所在的位置相对于DNS消息开始的偏移量。<br>  如：之前的header数组中出现过3www6google3com0,且处的位置为12,这里就可以用1100 000c 两个字节来代替3www6google3com0表示的16个字节</p>
<h3 id="TYPE值说明"><a href="#TYPE值说明" class="headerlink" title="TYPE值说明"></a><span id="rr_type">TYPE值说明</span></h3><h4 id="标准RR类型介绍"><a href="#标准RR类型介绍" class="headerlink" title="标准RR类型介绍"></a>标准RR类型介绍</h4><table>
<thead>
<tr>
<th align="center">类型</th>
<th>数值</th>
<th align="center">RFC来源</th>
<th align="left">描述</th>
<th align="left">功能</th>
</tr>
</thead>
<tbody><tr>
<td align="center">A</td>
<td>1</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">IP 地址记录</td>
<td align="left">传回一个 32 比特的 IPv4 地址，最常用于映射主机名称到IP地址，但也用于 DNSBL（<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1101">RFC 1101</a>）等。</td>
</tr>
<tr>
<td align="center">AAAA</td>
<td>28</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc3596">RFC 3596</a></td>
<td align="left">IPv6 IP 地址记录</td>
<td align="left">传回一个 128 比特的 IPv6 地址，最常用于映射主机名称到 IP 地址。</td>
</tr>
<tr>
<td align="center">AFSDB</td>
<td>18</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1183">RFC 1183</a></td>
<td align="left">AFS文件系统</td>
<td align="left">（Andrew File System）数据库核心的位置，于域名以外的 AFS 客户端常用来联系 AFS 核心。这个记录的子类型是被过时的<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/DCE/DFS">DCE/DFS</a>（DCE Distributed File System）所使用。</td>
</tr>
<tr>
<td align="center">APL</td>
<td>42</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc3123">RFC 3123</a></td>
<td align="left">地址前缀列表</td>
<td align="left">指定地址列表的范围，例如：CIDR 格式为各个类型的地址（试验性）。</td>
</tr>
<tr>
<td align="center">CAA</td>
<td>257</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc6844">RFC 6844</a></td>
<td align="left">权威认证授权</td>
<td align="left"><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/DNS%E8%AF%81%E4%B9%A6%E9%A2%81%E5%8F%91%E6%9C%BA%E6%9E%84%E6%8E%88%E6%9D%83">DNS认证机构授权</a>，限制主机/域的可接受的CA</td>
</tr>
<tr>
<td align="center">CDNSKEY</td>
<td>60</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc7344">RFC 7344</a></td>
<td align="left">子关键记录</td>
<td align="left">关键记录记录的子版本，用于转移到父级</td>
</tr>
<tr>
<td align="center">CDS</td>
<td>59</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc7344">RFC 7344</a></td>
<td align="left">子委托签发者</td>
<td align="left">委托签发者记录的子版本，用于转移到父级</td>
</tr>
<tr>
<td align="center">CERT</td>
<td>37</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4398">RFC 4398</a></td>
<td align="left">证书记录</td>
<td align="left">存储 PKIX、SPKI、PGP等。</td>
</tr>
<tr>
<td align="center">CNAME</td>
<td>5</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">规范名称记录</td>
<td align="left">一个主机名字的别名：域名系统将会继续尝试查找新的名字。</td>
</tr>
<tr>
<td align="center">DHCID</td>
<td>49</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4701">RFC 4701</a></td>
<td align="left">DHCP（动态主机设置协议）识别码</td>
<td align="left">用于将 FQDN 选项结合至 DHCP。</td>
</tr>
<tr>
<td align="center">DLV</td>
<td>32769</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4431">RFC 4431</a></td>
<td align="left">DNSSEC（域名系统安全扩展）来源验证记录</td>
<td align="left">为不在DNS委托者内发布DNSSEC的信任锚点，与 DS 记录使用相同的格式，<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc5074">RFC 5074</a>介绍了如何使用这些记录。</td>
</tr>
<tr>
<td align="center">DNAME</td>
<td>39</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2672">RFC 2672</a></td>
<td align="left">代表名称</td>
<td align="left">DNAME 会为名称和其子名称产生别名，与 CNAME 不同，在其标签别名不会重复。但与 CNAME 记录相同的是，DNS将会继续尝试查找新的名字。</td>
</tr>
<tr>
<td align="center">DNSKEY</td>
<td>48</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4034">RFC 4034</a></td>
<td align="left">DNS 关键记录</td>
<td align="left">于DNSSEC内使用的关键记录，与 KEY 使用相同格式。</td>
</tr>
<tr>
<td align="center">DS</td>
<td>43</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4034">RFC 4034</a></td>
<td align="left">委托签发者</td>
<td align="left">此记录用于鉴定DNSSEC已授权区域的签名密钥。</td>
</tr>
<tr>
<td align="center">HIP</td>
<td>55</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc5205">RFC 5205</a></td>
<td align="left">主机鉴定协议</td>
<td align="left">将端点标识符及IP 地址定位的分开的方法。</td>
</tr>
<tr>
<td align="center">IPSECKEY</td>
<td>45</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4025">RFC 4025</a></td>
<td align="left">IPSEC 密钥</td>
<td align="left">与 IPSEC 同时使用的密钥记录。</td>
</tr>
<tr>
<td align="center">KEY</td>
<td>25</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2535">RFC 2535</a> 和 <a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2930">RFC 2930</a></td>
<td align="left">关键记录</td>
<td align="left">只用于 SIG(0)（<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2931">RFC 2931</a>）及 TKEY（<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2930">RFC 2930</a>。<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc3455">RFC 3455</a> 否定其作为应用程序键及限制DNSSEC的使用。<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc3755">RFC 3755</a> 指定了 DNSKEY 作为DNSSEC的代替。</td>
</tr>
<tr>
<td align="center">LOC</td>
<td>29</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1876">RFC 1876</a></td>
<td align="left">位置记录</td>
<td align="left">将一个域名指定地理位置。</td>
</tr>
<tr>
<td align="center">MX</td>
<td>15</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">电邮交互记录</td>
<td align="left">引导域名到该域名的邮件传输代理（MTA, Message Transfer Agents）列表。</td>
</tr>
<tr>
<td align="center">NAPTR</td>
<td>35</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc3403">RFC 3403</a></td>
<td align="left">命名管理指针</td>
<td align="left">允许基于正则表达式的域名重写使其能够作为 URI 、进一步域名查找等。</td>
</tr>
<tr>
<td align="center">NS</td>
<td>2</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">名称服务器记录</td>
<td align="left">委托 DNS 域（DNS zone）使用已提供的权威域名服务器。</td>
</tr>
<tr>
<td align="center">NSEC</td>
<td>47</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4034">RFC 4034</a></td>
<td align="left">下一代安全记录</td>
<td align="left">DNSSEC 的一部分; 用来验证一个未存在的服务器，使用与 NXT（已过时）记录的格式。</td>
</tr>
<tr>
<td align="center">NSEC3</td>
<td>50</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc5155">RFC 5155</a></td>
<td align="left">NSEC 记录第三版</td>
<td align="left">用作允许未经允许的区域行走以证明名称不存在性的 DNSSEC 扩展。</td>
</tr>
<tr>
<td align="center">NSEC3PARAM</td>
<td>51</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc5155">RFC 5155</a></td>
<td align="left">NSEC3 参数</td>
<td align="left">与 NSEC3 同时使用的参数记录。</td>
</tr>
<tr>
<td align="center">OPENPGPKEY</td>
<td>61</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc7929">RFC 7929</a></td>
<td align="left">OpenPGP公钥记录</td>
<td align="left">基于DNS的域名实体认证方法，用于使用OPENPGPKEY DNS资源记录在特定电子邮件地址的DNS中发布和定位OpenPGP公钥。</td>
</tr>
<tr>
<td align="center">PTR</td>
<td>12</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">指针记录</td>
<td align="left">引导至一个规范名称（Canonical Name）。与 CNAME 记录不同，DNS“不会”进行进程，只会传回名称。最常用来运行反向 DNS 查找，其他用途包括引作DNS-SD。</td>
</tr>
<tr>
<td align="center">RRSIG</td>
<td>46</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4034">RFC 4034</a></td>
<td align="left">DNSSEC 证书</td>
<td align="left">DNSSEC 安全记录集证书，与 SIG 记录使用相同的格式。</td>
</tr>
<tr>
<td align="center">RP</td>
<td>17</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1183">RFC 1183</a></td>
<td align="left">负责人</td>
<td align="left">有关域名负责人的信息，电邮地址的 <strong>@</strong> 通常写为 <strong>a</strong>。</td>
</tr>
<tr>
<td align="center">SIG</td>
<td>24</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2535">RFC 2535</a></td>
<td align="left">证书</td>
<td align="left">SIG(0)（<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2931">RFC 2931</a>）及 TKEY（<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2930">RFC 2930</a>）使用的证书。<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc3755">RFC 3755</a> designated RRSIG as the replacement for SIG for use within DNSSEC.</td>
</tr>
<tr>
<td align="center">SOA</td>
<td>6</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">权威记录的起始</td>
<td align="left">指定有关DNS区域的权威性信息，包含主要名称服务器、域名管理员的电邮地址、域名的流水式编号、和几个有关刷新区域的定时器。</td>
</tr>
<tr>
<td align="center">SPF</td>
<td>99</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4408">RFC 4408</a></td>
<td align="left">SPF 记录</td>
<td align="left">作为 SPF 协议的一部分，优先作为先前在 TXT 存储 SPF 数据的临时做法，使用与先前在 TXT 存储的格式。</td>
</tr>
<tr>
<td align="center">SRV</td>
<td>33</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2782">RFC 2782</a></td>
<td align="left">服务定位器</td>
<td align="left">广义为服务定位记录，被新式协议使用而避免产生特定协议的记录，例如：MX 记录。</td>
</tr>
<tr>
<td align="center">SSHFP</td>
<td>44</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc4255">RFC 4255</a></td>
<td align="left">SSH 公共密钥指纹</td>
<td align="left">DNS 系统用来发布SSH公共密钥指纹的资源记录，以用作辅助验证服务器的真实性。</td>
</tr>
<tr>
<td align="center">TA</td>
<td>32768</td>
<td align="center">无</td>
<td align="left">DNSSEC 信任当局</td>
<td align="left">DNSSEC 一部分无签订 DNS 根目录的部署提案，，使用与 DS 记录相同的格式。</td>
</tr>
<tr>
<td align="center">TKEY</td>
<td>249</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2930">RFC 2930</a></td>
<td align="left">秘密密钥记录</td>
<td align="left">为 TSIG 提供密钥材料的其中一类方法，that is 在公共密钥下加密的 accompanying KEY RR。</td>
</tr>
<tr>
<td align="center">TSIG</td>
<td>250</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2845">RFC 2845</a></td>
<td align="left">DNS 密钥交易验证协议</td>
<td align="left">用以认证动态更新（Dynamic DNS）是来自合法的客户端，或与 DNSSEC 一样是验证回应是否来自合法的递归名称服务器。</td>
</tr>
<tr>
<td align="center">TXT</td>
<td>16</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">文本记录</td>
<td align="left">最初是为任意可读的文本 DNS 记录。自1990年起，些记录更经常地带有机读数据，以 <a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1464">RFC 1464</a>指定：opportunistic encryption、Sender Policy Framework（虽然这个临时使用的 TXT 记录在 SPF 记录推出后不被推荐）、DomainKeys、DNS-SD等。</td>
</tr>
<tr>
<td align="center">URI</td>
<td>256</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc7553">RFC 7553</a></td>
<td align="left">统一资源标识符</td>
<td align="left">可用于发布从主机名到URI的映射。</td>
</tr>
<tr>
<td align="center"><a target="_blank" rel="noopener" href="https://en.wikipedia.org/w/index.php?title=ZONEMD_record&action=edit&redlink=1">ZONEMD</a></td>
<td>63</td>
<td align="center">RFC 8976</td>
<td align="left">DNS 区域消息摘要</td>
<td align="left">在<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Cryptographic_message_digest">静态</a>DNS 区域数据上提供<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Cryptographic_message_digest">加密消息摘要</a></td>
</tr>
<tr>
<td align="center">SVCB</td>
<td>64</td>
<td align="center"><a target="_blank" rel="noopener" href="https://www.rfc-editor.org/rfc/rfc9460.html">RFC 9460</a></td>
<td align="left">服务绑定</td>
<td align="left">为需要解析许多资源以访问域的客户端提高性能的 RR。2023年11月正式确定rfc9460</td>
</tr>
<tr>
<td align="center">HTTPS</td>
<td>65</td>
<td align="center"><a target="_blank" rel="noopener" href="https://www.rfc-editor.org/rfc/rfc9460.html">RFC 9460</a></td>
<td align="left">专门针对http的svcb记录，为HTTP/HTTPS请求进行服务绑定</td>
<td align="left">为需要解析许多资源以访问域的客户端提高性能的 RR。 2023年11月正式确定 rfc9460</td>
</tr>
</tbody></table>
<h4 id="其他或伪资源记录类型"><a href="#其他或伪资源记录类型" class="headerlink" title="其他或伪资源记录类型"></a>其他或伪资源记录类型</h4><table>
<thead>
<tr>
<th align="center">类型</th>
<th>数值</th>
<th align="center">RFC来源</th>
<th align="left">描述</th>
<th align="left">功能</th>
</tr>
</thead>
<tbody><tr>
<td align="center">*</td>
<td>255</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">所有缓存的记录</td>
<td align="left">传回所有服务器已知类型的记录。如果服务器未有任何关于名称的记录，该请求将被转发。而传回的记录未必完全完成，例如：当一个名称有 A 及 MX 类型的记录时，但服务器已缓存了 A 记录，就只有 A 记录会被传回。</td>
</tr>
<tr>
<td align="center">AXFR</td>
<td>252</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1035">RFC 1035</a></td>
<td align="left">全域转移</td>
<td align="left">由主域名服务器转移整个区域文件至二级域名服务器。</td>
</tr>
<tr>
<td align="center">IXFR</td>
<td>251</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc1995">RFC 1995</a></td>
<td align="left">增量区域转移</td>
<td align="left">请求只有与先前流水式编号不同的特定区域的区域转移。此请求有机会被拒绝，如果权威服务器由于配置或缺乏必要的数据而无法履行请求，一个完整的（AXFR）会被发送以作回应。</td>
</tr>
<tr>
<td align="center"><span id=opt>OPT</span></td>
<td>41</td>
<td align="center"><a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc2671">RFC 2671</a>  已被<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc6891">RFC 6891</a>取代</td>
<td align="left">选项(optinon)</td>
<td align="left">这是一个“伪DNS 记录类型”，用于支持EDNS(0)。EDNS根据<a target="_blank" rel="noopener" href="https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11">OPTION-CODE</a>来确定传递的附加数据类型，从而决定传递的附加数据内容</td>
</tr>
</tbody></table>
<h4 id="已过时的RR类型"><a href="#已过时的RR类型" class="headerlink" title="已过时的RR类型"></a>已过时的RR类型</h4><table>
<thead>
<tr>
<th>类型</th>
<th>数值</th>
<th>RFC来源</th>
<th>被淘汰RFC</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>A6</td>
<td>38</td>
<td>RFC 2874</td>
<td>RFC 6563</td>
<td>Defined as part of early IPv6 but downgraded to experimental by RFC 3363; later downgraded to historic by RFC 6563.</td>
</tr>
<tr>
<td>APL</td>
<td>42</td>
<td>RFC 3123</td>
<td></td>
<td>Specify lists of address ranges, e.g. in <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing">CIDR</a> format, for various address families. Experimental.</td>
</tr>
<tr>
<td>EID</td>
<td>31</td>
<td>N/A</td>
<td></td>
<td>Defined by the <a target="_blank" rel="noopener" href="http://www.tools.ietf.org/html/draft-ietf-nimrod-dns-00">Nimrod DNS</a> <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Internet_draft">internet draft</a>, but never made it to RFC status. Not in current use by any notable application</td>
</tr>
<tr>
<td>GPOS</td>
<td>27</td>
<td>RFC 1712</td>
<td></td>
<td>A more limited early version of the LOC record</td>
</tr>
<tr>
<td>L32</td>
<td>105</td>
<td>RFC 6742</td>
<td></td>
<td>未被任何值得注意的应用程序使用并标记为“实验性”</td>
</tr>
<tr>
<td>L64</td>
<td>106</td>
<td>RFC 6742</td>
<td></td>
<td>未被任何值得注意的应用程序使用并标记为“实验性”</td>
</tr>
<tr>
<td>LP</td>
<td>107</td>
<td>RFC 6742</td>
<td></td>
<td>未被任何值得注意的应用程序使用并标记为“实验性”</td>
</tr>
<tr>
<td>MB</td>
<td>7</td>
<td>RFC 883</td>
<td>Not formally obsoleted. Unlikely to be ever adopted (RFC 2505).</td>
<td>MB, MG, MR, and MINFO are records to publish subscriber mailing lists. MAILB is a query code which returns one of those records. The intent was for MB and MG to replace the <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/SMTP">SMTP</a> VRFY and EXPN commands. MR was to replace the “551 User Not Local” SMTP error. Later, RFC 2505 recommended that both VRFY and EXPN be disabled, making MB and MG unnecessary. They were classified as experimental by RFC 1035.</td>
</tr>
<tr>
<td>MF</td>
<td>4</td>
<td>RFC 883</td>
<td>RFC 973</td>
<td>邮件目的地 (MD) 和邮件转发器 (MF) 记录；MAILA 不是实际的记录类型，而是返回 MF 和/或 MD 记录的查询类型。RFC 973 将这些记录替换为 MX 记录。</td>
</tr>
<tr>
<td>MG</td>
<td>8</td>
<td>RFC 883</td>
<td>没有正式过时。不太可能被采用（RFC 2505）。</td>
<td>MB、MG、MR 和 MINFO 是发布订阅者邮件列表的记录。MAILB 是一个查询代码，它返回这些记录之一。目的是让 MB 和 MG 替换<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/SMTP">SMTP</a> VRFY 和 EXPN 命令。MR 是为了替换“551 User Not Local”SMTP 错误。后来，RFC 2505 建议禁用 VRFY 和 EXPN，使 MB 和 MG 变得不必要。它们被 RFC 1035 归类为实验性的。</td>
</tr>
<tr>
<td>NB</td>
<td>32</td>
<td>RFC 1002</td>
<td></td>
<td>Mistakes (from RFC 1002); the numbers are now assigned to NIMLOC and SRV.</td>
</tr>
<tr>
<td>NSAP-PTR</td>
<td>23</td>
<td>RFC 1706</td>
<td></td>
<td>Not in current use by any notable application</td>
</tr>
<tr>
<td>NXT</td>
<td>30</td>
<td>RFC 2065</td>
<td>RFC 3755</td>
<td>Part of the first version of DNSSEC (RFC 2065). NXT was obsoleted by DNSSEC updates (RFC 3755). At the same time, the domain of applicability for KEY and SIG was also limited to not include DNSSEC use.</td>
</tr>
<tr>
<td>PX</td>
<td>26</td>
<td>RFC 2163</td>
<td></td>
<td>Not in current use by any notable application</td>
</tr>
<tr>
<td>RP</td>
<td>17</td>
<td>RFC 1183</td>
<td></td>
<td>RP may be used for certain human-readable information regarding a different contact point for a specific host, subnet, or other domain level label separate than that used in the SOA record.</td>
</tr>
<tr>
<td>SIG</td>
<td>24</td>
<td>RFC 2065</td>
<td>RFC 3755</td>
<td>DNSSEC 第一个版本 (RFC 2065) 的一部分。NXT 已被 DNSSEC 更新 (RFC 3755) 淘汰。同时，KEY 和 SIG 的适用范围也仅限于不包括 DNSSEC 的使用。</td>
</tr>
<tr>
<td>X25</td>
<td>19</td>
<td>RFC 1183</td>
<td></td>
<td>Not in current use by any notable application</td>
</tr>
<tr>
<td>WKS</td>
<td>11</td>
<td>RFC 883, RFC 1035</td>
<td>Declared as “not to be relied upon” by RFC 1123 (more in RFC 1127).</td>
<td>Record to describe well-known services supported by a host. Not used in practice. The current recommendation and practice is to determine whether a service is supported on an IP address by trying to connect to it. SMTP is even prohibited from using WKS records in MX processing.[<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/List_of_DNS_record_types#cite_note-rfc1123-14">14]</a></td>
</tr>
<tr>
<td>SINK</td>
<td>40</td>
<td>N/A</td>
<td></td>
<td>Defined by the <a target="_blank" rel="noopener" href="http://www.tools.ietf.org/html/draft-eastlake-kitchen-sink">Kitchen Sink</a> <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Internet_draft">internet draft</a>, but never made it to RFC status</td>
</tr>
<tr>
<td>NID</td>
<td>104</td>
<td>RFC 6742</td>
<td></td>
<td>Not in use by any notable application and marked as “experimental”</td>
</tr>
<tr>
<td>UINFO</td>
<td>100</td>
<td>N/A</td>
<td></td>
<td>IANA reserved, no RFC documented them [<a target="_blank" rel="noopener" href="https://web.archive.org/web/20080611185015/http://www.ops.ietf.org/lists/namedroppers/namedroppers.2004/msg00949.html">1]</a> and support was removed from <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/BIND">BIND</a> in the early 90s.</td>
</tr>
<tr>
<td>HINFO</td>
<td>13</td>
<td>RFC 883</td>
<td>Unobsoleted by RFC 8482. Currently used by <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Cloudflare">Cloudflare</a> in response to queries of the type ANY.[<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/List_of_DNS_record_types#cite_note-CF-HINFO-15">15]</a></td>
<td>Record intended to provide information about host CPU type and operating system. It was intended to allow protocols to optimize processing when communicating with similar peers.</td>
</tr>
<tr>
<td>NINFO</td>
<td>56</td>
<td>N/A</td>
<td></td>
<td>Used to provide status information about a zone. Requested for the IETF draft “The Zone Status (ZS) DNS Resource Record” in 2008. Expired without adoption.[<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/List_of_DNS_record_types#cite_note-IETF-dnsext-zs-19">19]</a></td>
</tr>
<tr>
<td>MR</td>
<td>9</td>
<td>RFC 883</td>
<td>没有正式过时。不太可能被采用（RFC 2505）。</td>
<td>MB、MG、MR 和 MINFO 是发布订阅者邮件列表的记录。MAILB 是一个查询代码，它返回这些记录之一。目的是让 MB 和 MG 替换<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/SMTP">SMTP</a> VRFY 和 EXPN 命令。MR 是为了替换“551 User Not Local”SMTP 错误。后来，RFC 2505 建议禁用 VRFY 和 EXPN，使 MB 和 MG 变得不必要。它们被 RFC 1035 归类为实验性的。</td>
</tr>
<tr>
<td>MD</td>
<td>3</td>
<td>RFC 883</td>
<td>RFC 973</td>
<td>Mail destination (MD) and mail forwarder (MF) records; MAILA is not an actual record type, but a query type which returns MF and/or MD records. RFC 973 replaced these records with the MX record.</td>
</tr>
<tr>
<td>NSAP</td>
<td>22</td>
<td>RFC 1706</td>
<td></td>
<td>Not in current use by any notable application</td>
</tr>
<tr>
<td>NBSTAT</td>
<td>33</td>
<td>RFC 1002</td>
<td></td>
<td>错误（来自 RFC 1002）；编号现在分配给 NIMLOC 和 SRV。</td>
</tr>
<tr>
<td>TALINK</td>
<td>58</td>
<td>N/A</td>
<td></td>
<td>Defined by the <a target="_blank" rel="noopener" href="https://tools.ietf.org/html/draft-wijngaards-dnsop-trust-history-02">DNSSEC Trust Anchor History Service</a> <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Internet_draft">internet draft</a>, but never made it to RFC status</td>
</tr>
<tr>
<td>RKEY</td>
<td>57</td>
<td>N/A</td>
<td></td>
<td>Used for encryption of NAPTR records. Requested for the IETF draft “The RKEY DNS Resource Record” in 2008. Expired without adoption.[<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/List_of_DNS_record_types#cite_note-IETF-dnsext-rkey-20">20]</a></td>
</tr>
<tr>
<td>NIMLOC</td>
<td>32</td>
<td>N/A</td>
<td></td>
<td>由<a target="_blank" rel="noopener" href="http://www.tools.ietf.org/html/draft-ietf-nimrod-dns-00">Nimrod DNS</a> <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Internet_draft">互联网草案</a>定义，但从未达到 RFC 状态。当前未由任何显着应用程序使用</td>
</tr>
<tr>
<td>ATMA</td>
<td>34</td>
<td>N/A</td>
<td></td>
<td>Defined by The ATM Forum Committee.[<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/List_of_DNS_record_types#cite_note-AF-DANS-0152-16">16]</a></td>
</tr>
<tr>
<td>NULL</td>
<td>10</td>
<td>RFC 883</td>
<td>RFC 1035</td>
<td>Obsoleted by RFC 1035. RFC 883 defined “completion queries” (opcode 2 and maybe 3) which used this record. RFC 1035 later reassigned opcode 2 to be “status” and reserved opcode 3.</td>
</tr>
<tr>
<td>MINFO</td>
<td>14</td>
<td>RFC 883</td>
<td>没有正式过时。不太可能被采用（RFC 2505）。</td>
<td>MB、MG、MR 和 MINFO 是发布订阅者邮件列表的记录。MAILB 是一个查询代码，它返回这些记录之一。目的是让 MB 和 MG 替换<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/SMTP">SMTP</a> VRFY 和 EXPN 命令。MR 是为了替换“551 User Not Local”SMTP 错误。后来，RFC 2505 建议禁用 VRFY 和 EXPN，使 MB 和 MG 变得不必要。它们被 RFC 1035 归类为实验性的。</td>
</tr>
<tr>
<td>UID</td>
<td>101</td>
<td>N/A</td>
<td></td>
<td>IANA 保留，没有 RFC 记录它们[<a target="_blank" rel="noopener" href="https://web.archive.org/web/20080611185015/http://www.ops.ietf.org/lists/namedroppers/namedroppers.2004/msg00949.html">1]</a>并且在 90 年代初从<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/BIND">BIND</a>中删除了支持。</td>
</tr>
<tr>
<td>DOA</td>
<td>259</td>
<td>N/A</td>
<td></td>
<td>Defined by the <a target="_blank" rel="noopener" href="https://tools.ietf.org/html/draft-durand-doa-over-dns-03">DOA over DNS</a> <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Internet_draft">internet draft</a>, but never made it to RFC status</td>
</tr>
<tr>
<td>ISDN</td>
<td>20</td>
<td>RFC 1183</td>
<td></td>
<td>Not in current use by any notable application</td>
</tr>
<tr>
<td>UNSPEC</td>
<td>103</td>
<td>N/A</td>
<td></td>
<td>IANA 保留，没有 RFC 记录它们[<a target="_blank" rel="noopener" href="https://web.archive.org/web/20080611185015/http://www.ops.ietf.org/lists/namedroppers/namedroppers.2004/msg00949.html">1]</a>并且在 90 年代初从<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/BIND">BIND</a>中删除了支持。</td>
</tr>
<tr>
<td>RT</td>
<td>21</td>
<td>RFC 1183</td>
<td></td>
<td>Not in current use by any notable application</td>
</tr>
<tr>
<td>MAILA</td>
<td>254</td>
<td>RFC 883</td>
<td>RFC 973</td>
<td>邮件目的地 (MD) 和邮件转发器 (MF) 记录；MAILA 不是实际的记录类型，而是返回 MF 和/或 MD 记录的查询类型。RFC 973 将这些记录替换为 MX 记录。</td>
</tr>
<tr>
<td>GID</td>
<td>102</td>
<td>N/A</td>
<td></td>
<td>IANA 保留，没有 RFC 记录它们[<a target="_blank" rel="noopener" href="https://web.archive.org/web/20080611185015/http://www.ops.ietf.org/lists/namedroppers/namedroppers.2004/msg00949.html">1]</a>并且在 90 年代初从<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/BIND">BIND</a>中删除了支持。</td>
</tr>
<tr>
<td>MAILB</td>
<td>253</td>
<td>RFC 883</td>
<td>没有正式过时。不太可能被采用（RFC 2505）。</td>
<td>MB、MG、MR 和 MINFO 是发布订阅者邮件列表的记录。MAILB 是一个查询代码，它返回这些记录之一。目的是让 MB 和 MG 替换<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/SMTP">SMTP</a> VRFY 和 EXPN 命令。MR 是为了替换“551 User Not Local”SMTP 错误。后来，RFC 2505 建议禁用 VRFY 和 EXPN，使 MB 和 MG 变得不必要。它们被 RFC 1035 归类为实验性的。</td>
</tr>
<tr>
<td>KEY</td>
<td>25</td>
<td>RFC 2065</td>
<td>RFC 3755</td>
<td>DNSSEC 第一个版本 (RFC 2065) 的一部分。NXT 已被 DNSSEC 更新 (RFC 3755) 淘汰。同时，KEY 和 SIG 的适用范围也仅限于不包括 DNSSEC 的使用。</td>
</tr>
<tr>
<td>SPF</td>
<td>99</td>
<td>RFC 4408</td>
<td>RFC 7208</td>
<td>Specified as part of the <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Sender_Policy_Framework">Sender Policy Framework</a> protocol as an alternative to storing SPF data in TXT records, using the same format. Support for it was discontinued in RFC 7208 due to widespread lack of support.[<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/List_of_DNS_record_types#cite_note-IETF-RFC6686-17">17]</a>[<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/List_of_DNS_record_types#cite_note-IETF-RFC7208-18">18]</a></td>
</tr>
</tbody></table>
<h2 id="RR格式详解"><a href="#RR格式详解" class="headerlink" title="RR格式详解"></a>RR格式详解</h2><h3 id="SRV"><a href="#SRV" class="headerlink" title="SRV"></a>SRV</h3><p>DNS SRV是DNS记录中一种，用来指定服务地址。与常见的A记录、cname不同的是，SRV中除了记录<strong>服务器</strong>的地址，还记录了<strong>服务</strong>的端口，并且可以设置每个服务地址的优先级和权重。访问服务的时候，本地的DNS resolver从DNS服务器查询到一个地址列表，根据优先级和权重，从中选取一个地址作为本次请求的目标地址。</p>
<h4 id="应用场景"><a href="#应用场景" class="headerlink" title="应用场景"></a>应用场景</h4><p>一个能够支持SRV的LDAP client可以通过查询域名，得知LDAP服务的IP地址和服务端口：</p>
<figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs reasonml"><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">_ldap</span>.</span><span class="hljs-module"><span class="hljs-identifier">_tcp</span>.</span></span>example.com<br></code></pre></td></tr></table></figure>

<p>这个域名的格式是<a target="_blank" rel="noopener" href="https://datatracker.ietf.org/doc/html/rfc2782">rfc-2782</a>中推荐的格式，_ldap表示LDAP服务，_tcp表示通过TCP协议访问LDAP服务。</p>
<h4 id="SRV的记录格式"><a href="#SRV的记录格式" class="headerlink" title="SRV的记录格式:"></a>SRV的记录格式:</h4><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-section">  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br>|                                               |<br>/                                               /<br>/            _Service._Proto.Name               /<br><span class="hljs-section">|                                               |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                      33                       |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                     CLASS                     |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br>|                      TTL                      |<br><span class="hljs-section">|                                               |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br>|                   RDLENGTH                    |<br><span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--<span class="hljs-code">+--+</span>--|<br>/                     RDATA                     /<br><span class="hljs-section">/                                               /</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br></code></pre></td></tr></table></figure>
<h5 id="Service-Proto-Name-格式说明"><a href="#Service-Proto-Name-格式说明" class="headerlink" title="_Service._Proto.Name 格式说明"></a>_Service._Proto.Name 格式说明</h5><table>
<thead>
<tr>
<th>标签名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>_Service</td>
<td>服务名称，前缀“_”是为防止与DNS Label（普通域名）冲突。</td>
</tr>
<tr>
<td>_Proto</td>
<td>服务使用的通信协议，_TCP、_UDP、其它标准协议或者自定义的协议。前缀“_”是为防止与DNS Label（普通域名）冲突</td>
</tr>
<tr>
<td>Name</td>
<td>提供服务的域名。</td>
</tr>
<tr>
<td>TTL/ CLASS及RDLENGTH</td>
<td>参考<a href="#rr_format">《RR记录格式》</a>的标准含义</td>
</tr>
</tbody></table>
<h5 id="RDATA格式为"><a href="#RDATA格式为" class="headerlink" title="RDATA格式为:"></a>RDATA格式为:</h5><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-section">  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                  Priority                     |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                    Weight                     |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br><span class="hljs-section">|                    Port                       |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br>|                                               |<br>/                                               /<br>/                    Target                     /<br><span class="hljs-section">|                                               |</span><br><span class="hljs-section">+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span><br></code></pre></td></tr></table></figure>
<h5 id="RDATA字段含义如下："><a href="#RDATA字段含义如下：" class="headerlink" title="RDATA字段含义如下："></a>RDATA字段含义如下：</h5><table>
<thead>
<tr>
<th>字段名</th>
<th>长度</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>Priority</td>
<td>2字节</td>
<td>无符号整形</td>
<td>该记录的优先级，数值越小表示优先级越高，范围0-65535。</td>
</tr>
<tr>
<td>Weight</td>
<td>2字节</td>
<td>无符号整形</td>
<td>该记录的权重，数值越高权重越高，范围0-65535。</td>
</tr>
<tr>
<td>Port</td>
<td>2字节</td>
<td>无符号整形</td>
<td>服务端口号，0-65535。</td>
</tr>
<tr>
<td>Target</td>
<td></td>
<td>标签字符串</td>
<td>目标主机对应的域名。 此域名必须有一个或多个地址记录(A或AAAA记录)，此域名不能是别名（在 RFC 1034 或 RFC 2181 的意义上）。 建议并不强制要求在应答数据的附加数据部分返回此地址记录数据。 除非未来的标准允许，否则此名称不能使用<a href="#compress">标签压缩</a>。<br>“.” 代表该服务在此域中绝对不可用。</td>
</tr>
</tbody></table>
<p>客户端查询到多条记录的时候，使用优先级最高的记录。</p>
<p>对相同优先级的记录，按照权重选择，记录的权重越高，被选择的可能性越高。</p>
<p>选择的时候，将所有记录的权重值累加，得到一个选择区间[0,sum]，每个记录在[0,sum]中占据一段连续的、长度为自身权重值区间。然后生成一个[0,sum]中的随机数，随机数落在的区间所属的记录就是被选择的记录。</p>
<h4 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h4><ol>
<li><p>在使用DNS SRV的时候，要注意DNS Client是否按照预期的方式处理收到的SRV记录。当前DNS SRV只能够负责提供服务地址列表，对这个列表如何解读，完全取决于Client的实现。</p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://datatracker.ietf.org/doc/html/rfc1035">rfc-1035</a>中规定，通过UDP协议传输DNS响应时，UDP报文的<strong>负载</strong>不能超过512字节，在添加SRV记录的时候，要特别注意。（通过TCP传输时没有512字节的限制）</p>
</li>
<li><p>当一个服务地址有多个相同优先级的SRV记录的时候，Client会按照这些SRV的权重分配请求。下一次向服务发起的请求可能是发送到了另一个地址。</p>
</li>
<li><p>在通过SRV记录的权重来分配请求的时候，使用的是本地缓存的DNS记录，所以不能实时地感知到服务的地址列表变化。除非将TTL设置的非常短暂，但这样将会频繁地查询DNS服务器。</p>
</li>
</ol>
<h4 id="示例如下"><a href="#示例如下" class="headerlink" title="示例如下"></a>示例如下</h4><img src="/2020/08/26/03%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91/03linux/01DNS%E5%8D%8F%E8%AE%AE/srv.png" srcset="/img/loading.gif" lazyload class="" title="SRV应答">

<h1 id="EDNS-DNS扩展机制"><a href="#EDNS-DNS扩展机制" class="headerlink" title="EDNS( DNS扩展机制)"></a>EDNS( DNS扩展机制)</h1><p>EDNS即Extension Mechanisms for DNS。最新定义在<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/rfc6891">RFC 6891</a>(替换了RFC2671)向DNS添加了扩展机制。EDNS在遵循已有的<a href="#dformat">DNS报文格式</a>的基础上增加一些字段，来支持更多的DNS请求业务，许多新的DNS使用和协议扩展依赖于这些扩展的存在。</p>
<p>需要注意的是，像DNS服务器这样一个大型且广泛应用的系统软件，新增加扩展协议的时候一定要考虑到向后兼容性(backward compatibility)，即你增加了你这个特性的消息传输给未支持该特性的服务器时，后者依然能正确处理。</p>
<p>EDNS是DNS的逐跳( hop-by-hop )扩展。</p>
<p>EDNS0是第一个被广泛使用的EDNS协议版本。它提供了DNS消息的扩展格式，允许DNS协议支持更大的消息长度和更多的资源记录类型. EDNS(1)也是一种DNS协议扩展，用于增加DNS消息中的额外信息字段，与EDNS(0)相比，EDNS(1)的扩展性能更强</p>
<h2 id="为什么要有EDNS？"><a href="#为什么要有EDNS？" class="headerlink" title="为什么要有EDNS？"></a>为什么要有EDNS？</h2><p>RFC2671中指出EDNS被提出来的几个理由：</p>
<ul>
<li><p>DNS协议头部的第二个16字节中都已经被用的差不多了，需要添加新的返回类型(RCODE)和标记(FLAGS)来支持其他需求；</p>
</li>
<li><p>只为标示domain类型的标签分配了两位，现在已经用掉了两位（00标示字符串类型，11表示压缩类型），后面如果有更多的标签类型则无法支持；</p>
</li>
<li><p>当初DNS协议中设计的用UDP包传输时包大小限制为512字节，现在很多主机已经具备重组大数据包的能力，所以要有一种机制来允许DNS请求方通知DNS服务器让其返回大包；</p>
</li>
</ul>
<p>以后我们会看到，<a href="#dnssec">DNSSEC机制(DNS Security Extensions)</a>和<a href="#ecs">ECS(edns-client-subnet)机制</a>等都需要有EDNS的支持。</p>
<h2 id="EDNS的内容是什么"><a href="#EDNS的内容是什么" class="headerlink" title="EDNS的内容是什么"></a>EDNS的内容是什么</h2><p>怎样在DNS消息协议的基础上再增加一些字段呢？为了保持向后兼容性，更改已有的DNS协议格式是不可能的，所以只能在DNS协议的数据部分中做文章。</p>
<p>由此，EDNS中引入了一种新的<a href="#opt">伪资源记录 OPT</a>（一种特殊的RR），之所以叫做伪资源记录是因为它不包含任何DNS数据，OPT RR不能被cache、不能被转发、不能被存储在zone文件中。OPT被放在DNS通信双方（requestor和responsor）DNS消息的<a href="#additional"><strong>Additional</strong></a>区域中。</p>
<h2 id="OPT-伪RR介绍"><a href="#OPT-伪RR介绍" class="headerlink" title="OPT 伪RR介绍"></a>OPT 伪RR介绍</h2><p>OPT RR 有时称为meta RR一般存放在<a href="#additional"><strong>Additional</strong></a>区域中。其对应的<a href="#opt">RR TYPE</a>值为41 。</p>
<h3 id="线状数据格式表示"><a href="#线状数据格式表示" class="headerlink" title="线状数据格式表示"></a>线状数据格式表示</h3><p>OPT RR遵循<a href="#rr_format">标准RR格式</a>，但相关的含义会和<a href="#rr_format">标准的RR格式</a>有些差别，每个字段定义如下：</p>
<figure class="highlight gherkin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs gherkin">+------------+--------------+------------------------------+<br>|<span class="hljs-string"> Field Name </span>|<span class="hljs-string"> Field Type   </span>|<span class="hljs-string"> Description                  </span>|<br>+------------+--------------+------------------------------+<br>|<span class="hljs-string"> NAME       </span>|<span class="hljs-string"> domain name  </span>|<span class="hljs-string"> MUST be 0 (root domain)      </span>|<span class="hljs-string"> 固定为空</span><br><span class="hljs-string"></span>|<span class="hljs-string"> TYPE       </span>|<span class="hljs-string"> u_int16_t    </span>|<span class="hljs-string"> OPT (41)                     </span>|<span class="hljs-string"> 固定为41(0x29)</span><br><span class="hljs-string"></span>|<span class="hljs-string"> CLASS      </span>|<span class="hljs-string"> u_int16_t    </span>|<span class="hljs-string"> requestor&#x27;s UDP payload size </span>|<span class="hljs-string"> </span><br><span class="hljs-string"></span>|<span class="hljs-string"> TTL        </span>|<span class="hljs-string"> u_int32_t    </span>|<span class="hljs-string"> extended RCODE and flags     </span>|<span class="hljs-string"> 扩展的DNS消息头部</span><br><span class="hljs-string"></span>|<span class="hljs-string"> RDLEN      </span>|<span class="hljs-string"> u_int16_t    </span>|<span class="hljs-string"> length of all RDATA          </span>|<br>|<span class="hljs-string"> RDATA      </span>|<span class="hljs-string"> octet stream </span>|<span class="hljs-string"> &#123;attribute,value&#125; pairs      </span>|<span class="hljs-string"> KV类型的可变部分</span><br><span class="hljs-string">+------------+--------------+------------------------------+</span><br></code></pre></td></tr></table></figure>

<h4 id="TTL字段说明"><a href="#TTL字段说明" class="headerlink" title="TTL字段说明"></a>TTL字段说明</h4><p>原来的TTL字段被用来存储扩展消息头部中的RCODE和flags，它的格式如下：</p>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs jboss-cli">              +0 <span class="hljs-params">(MSB)</span>                            +1 <span class="hljs-params">(LSB)</span><br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>0: |         EXTENDED-RCODE        |            VERSION            |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>2: | DO|                           Z                               |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br></code></pre></td></tr></table></figure>

<p>EXTENDED-RCODE<br>      高位8个bit是扩展RCODE(返回状态码)，这8个bit加上DNS头部的4bit总共有12bit(8bit在高位),这样就可以表示更多的返回类型；<br>      Forms the upper 8 bits of extended 12-bit RCODE (together with the<br>      4 bits defined in [RFC1035].  Note that EXTENDED-RCODE value 0<br>      indicates that an unextended RCODE is in use (values 0 through<br>      15).</p>
<p>   VERSION<br>      表示EDNS的版本（EDNS根据支持不同的扩展内容会有很多版本）,<br>      Indicates the implementation level of the setter.  Full<br>      conformance with this specification is indicated by version ‘0’.<br>      Requestors are encouraged to set this to the lowest implemented<br>      level capable of expressing a transaction, to minimise the<br>      responder and network load of discovering the greatest common<br>      implementation level between requestor and responder.  A<br>      requestor’s version numbering strategy MAY ideally be a run-time<br>      configuration option.<br>      If a responder does not implement the VERSION level of the<br>      request, then it MUST respond with RCODE=BADVERS.  All responses<br>      MUST be limited in format to the VERSION level of the request, but<br>      the VERSION of each response SHOULD be the highest implementation<br>      level of the responder.  In this way, a requestor will learn the<br>      implementation level of a responder as a side effect of every<br>      response, including error responses and including RCODE=BADVERS.</p>
<h4 id="RDATA-字段说明"><a href="#RDATA-字段说明" class="headerlink" title="RDATA 字段说明"></a><span id=opt_rdata>RDATA 字段说明</span></h4><p>RDATA中可能包含零个或多个<code>option</code>。每个<code>option</code>必须视为一个位字段。每个<code>option</code>的格式如下：</p>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs jboss-cli">              +0 <span class="hljs-params">(MSB)</span>                            +1 <span class="hljs-params">(LSB)</span><br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>0: |                          OPTION-CODE                          |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>2: |                         OPTION-LENGTH                         |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>4: |                                                               |<br>   /                          OPTION-DATA                          /<br>   /                                                               /<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br></code></pre></td></tr></table></figure>

<p>OPTION-CODE ：由IANA分配，<a target="_blank" rel="noopener" href="https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11">参考</a></p>
<p>OPTION-LENGTH: OPTION-DATA的长度</p>
<p>OPTION-DATA: OPTION-CODE对应的内容, 具体实现依赖于具体RFC定义，如<a href="#ecs_option">ECS</a></p>
<h2 id="EDNS-应用实现"><a href="#EDNS-应用实现" class="headerlink" title="EDNS 应用实现"></a>EDNS 应用实现</h2><h3 id="ECS"><a href="#ECS" class="headerlink" title="ECS "></a><span id=ecs>ECS </span></h3><p>ECS即ENS Client Subnet。 是EDNS(0)中的一个OPT，它允许递归 DNS 解析器为其代表进行DNS查询的主机或客户端指定子网。这通常旨在通过允许更好地使用基于 DNS 的负载平衡来在客户端计算机不一定靠近递归解析器时选择客户端附近的服务地址，从而帮助加快从内容传递网络传递数据的速度。</p>
<p>ECS 的详细内容可参考<a target="_blank" rel="noopener" href="https://datatracker.ietf.org/doc/html/rfc7871">RFC7871</a>。</p>
<h4 id="ECS-option-数据格式"><a href="#ECS-option-数据格式" class="headerlink" title="ECS option 数据格式"></a><span id=ecs_option>ECS option 数据格式</span></h4><p>ECS基于设置<a href="#opt_rdata">OPT伪RR的RDATA</a>来实现的。</p>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs jboss-cli">             +0 <span class="hljs-params">(MSB)</span>                            +1 <span class="hljs-params">(LSB)</span><br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>0: |                          OPTION-CODE                          |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>2: |                         OPTION-LENGTH                         |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>4: |                            FAMILY                             |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>6: |     SOURCE PREFIX-LENGTH      |     SCOPE PREFIX-LENGTH       |<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br>8: |                           ADDRESS.<span class="hljs-string">..</span>                          /<br>   +<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<span class="hljs-params">---</span>+<br></code></pre></td></tr></table></figure>

<ul>
<li>OPTION-CODE： 长度为2个字节，固定为 8 (0x00 0x80)由 <a target="_blank" rel="noopener" href="https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11">IANA</a> 统一规定对应的编码序号。</li>
<li>OPTION-LENGTH：长度为2个字节，代表了后续的FAMILY、 SOURCE PREFIX-LENGTH 、SCOPE PREFIX-LENGTH  、ADDRESS等内容的总长度。</li>
<li>FAMILY：2个字节，标识ADDRESS的地址族，由<a target="_blank" rel="noopener" href="https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml">IANA</a>统一确定地址族编码序号，ipv4为1，ipv6为2</li>
<li>SOURCE PREFIX-LENGTH：1个字节，标识要查找的<code>ADDRESS</code>数据的最左边的有效位数即IP地址<code>ADDRESS </code>宏的网络号的位数,ipv4最大32，ipv6最大128。在应答结果中返回请求时指定的网络号的位数</li>
<li>SCOPE PREFIX-LENGTH ：在查询请求中固定为0；在应答数据中标识应答数据<code>ADDRESS</code>的最左边的有效位数即IP地址<code>ADDRESS </code>的网络号的位数</li>
<li>ADDRESS：就是设置的SubNet的IP地址,依据上面的FAMILY</li>
</ul>
<h3 id="DNSSEC"><a href="#DNSSEC" class="headerlink" title="DNSSEC"></a><span id=dnssec>DNSSEC</span></h3><p>DNSSEC( DNS Security Extensions) 即DNS安全扩展.DNSSEC是一种基于EDNS0的协议扩展，用于提供DNS域名解析的安全性和完整性。DNSSEC可以保护DNS查询和响应的完整性，防止DNS欺骗攻击和DNS污染攻击</p>
<h1 id="什么是SOA？"><a href="#什么是SOA？" class="headerlink" title="什么是SOA？"></a>什么是SOA？</h1><p>SOA，即Start Of Authority，放在 zone file 中，用于描述这个 zone 负责的 name server，version number…等资料，以及当 slave server 要备份这个 zone 时的一些参数。</p>
<p>每个 zone file 中必须有且仅有一条 SOARR ，并在 zone file 中作为第一条资源记录保存。</p>
<p>举个栗子：</p>
<figure class="highlight llvm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs llvm">@ IN SOA lv<span class="hljs-number">3</span>ns<span class="hljs-number">1</span>.ffdns.net. webmaster.ffdns.net. (<br>    <span class="hljs-number">2009092868</span> <span class="hljs-comment">; Serial</span><br>    <span class="hljs-number">604800</span> <span class="hljs-comment">; Refresh</span><br>    <span class="hljs-number">3600</span> <span class="hljs-comment">; Retry</span><br>    <span class="hljs-number">2419200</span> <span class="hljs-comment">; Expire</span><br>    <span class="hljs-number">3600</span> ) <span class="hljs-comment">; Minimum</span><br></code></pre></td></tr></table></figure>

<blockquote>
<p><strong>第一行：</strong><code>@</code>指代该 zone ； <code>lv3ns1.ffdns.net.</code>是该 zone 的授权主机；<code>webmaster.ffdns.net.</code>代表[<code>webmaster@ffdns.net](mailto:</code><a href="mailto:&#x77;&#x65;&#98;&#x6d;&#97;&#x73;&#x74;&#101;&#114;&#64;&#102;&#x66;&#100;&#x6e;&#x73;&#46;&#110;&#101;&#116;">&#x77;&#x65;&#98;&#x6d;&#97;&#x73;&#x74;&#101;&#114;&#64;&#102;&#x66;&#100;&#x6e;&#x73;&#46;&#110;&#101;&#116;</a>)`，即该 zone 的管理者信箱。</p>
<p><strong>Serial：</strong>代表 zone file 的版本，每当 zone file 内容有变动，name server 管理者就应该增加这个号码，因为 slave 会将这个号码与其 copy 的那份比对以便决定是否要再 copy 一次（即进行 zone transfer ）。</p>
<p><strong>Refresh：</strong> slave server 每隔这段时间(秒)，就去检查 master server 上的 serial number 。</p>
<p><strong>Retry：</strong>当 slave server 无法和 master 进行 serial check 时，要每隔这段时间（秒） retry 一次。</p>
<p><strong>Expire：</strong>当时间超过 Expire 所定的秒数而 slave server 都无法和 master 取得连络，那么 slave 会删除自己的这份 copy 。</p>
<p><strong>Minimum：</strong>代表这个 zone file 中所有 record 的内定的 TTL 值，也就是其它的 DNS server cache 这笔 record 时，最长不应该超过这个时间。</p>
</blockquote>
<h1 id="名词解释"><a href="#名词解释" class="headerlink" title="名词解释"></a>名词解释</h1><table>
<thead>
<tr>
<th>名词</th>
<th>解释</th>
</tr>
</thead>
<tbody><tr>
<td>逐跳扩展</td>
<td>是一种网络协议设计中的扩展方式，它允许协议在数据包中添加自定义的扩展选项，而这些选项会在每一跳节点上进行处理和解析。<br>在逐跳扩展中，数据包会携带一个或多个扩展选项，这些选项在每一个跳的节点上被处理，然后转发到下一个节点。每一个节点只负责处理自己的扩展选项，而不影响其他选项或者原始数据包的内容。因此，逐跳扩展是一种比较灵活的扩展方式，能够让协议在不影响基本功能的情况下，添加额外的功能和特性。<br>逐跳扩展常常用于一些底层协议中，如IP协议、IPv6协议等。在这些协议中，逐跳扩展可以用来添加一些新的路由或者策略信息，或者用于网络诊断和测试等用途。另外，在一些应用层协议中，也可能会采用逐跳扩展，如DNS协议中的EDNS扩展就是一种基于逐跳扩展的设计。</td>
</tr>
</tbody></table>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/cobbliu/p/3188632.html">https://www.cnblogs.com/cobbliu/p/3188632.html</a></p>
<p><a target="_blank" rel="noopener" href="https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11">https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11</a></p>
<p><a target="_blank" rel="noopener" href="https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml">https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml</a></p>
<p><a target="_blank" rel="noopener" href="https://asutorufa.github.io/posts/668530ca/">https://asutorufa.github.io/posts/668530ca/</a></p>
<p><a target="_blank" rel="noopener" href="https://www.lijiaocn.com/%E6%8A%80%E5%B7%A7/2017/03/06/dns-srv.html">https://www.lijiaocn.com/%E6%8A%80%E5%B7%A7/2017/03/06/dns-srv.html</a><br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/27c3f95e7509">https://www.jianshu.com/p/27c3f95e7509</a></p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91/">软件开发</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/linux/">linux</a>
                    
                      <a class="hover-with-bg" href="/tags/dns/">dns</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/08/27/04DevOps/08Python%E5%86%85%E7%BD%AE%E7%9A%84SimpleHTTPServer%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Python 内置的SimpleHTTPServer使用指南</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/08/26/03%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91/03linux/00DNS%E5%9F%BA%E7%A1%80/">
                        <span class="hidden-mobile">DNS基础</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
